package com.epfresh.delegate;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PointF;
import android.text.InputFilter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.activity.DetailGoodsActivity;
import com.epfresh.activity.*;
import com.epfresh.activity.LoginActivity;
import com.epfresh.adapter.CategoryGoodsAdapter;
import com.epfresh.adapter.DeliveryStoreListAdapter;
import com.epfresh.api.entity.*;
import com.epfresh.api.entity.RequestEntityMap;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.entity.TagPager;
import com.epfresh.api.global.AppActivity;
import com.epfresh.api.helper.ApplicationHelper;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.utils.CashierInputFilter;
import com.epfresh.api.utils.JsonUtils;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.list.LoadMoreListView;
import com.epfresh.api.widget.ptr.PtrDefaultHandler;
import com.epfresh.api.widget.ptr.PtrFrameLayout;
import com.epfresh.api.widget.ptr.PtrHandler;
import com.epfresh.api.widget.ptr.PtrMdFrameLayout;
import com.epfresh.bean.AddCarResponse;
import com.epfresh.bean.CarCntResponse;
import com.epfresh.bean.ContentEntity;
import com.epfresh.bean.GoodsParameters;
import com.epfresh.bean.ListGoods;
import com.epfresh.bean.ProductCategory;
import com.epfresh.bean.StoreDetail;
import com.epfresh.global.BaseActivity;
import com.epfresh.global.CartHelper;
import com.epfresh.global.DataManager;
import com.epfresh.utils.FormatUtil;
import com.epfresh.views.FakeAddImageView;
import com.epfresh.views.MultiStateView;
import com.epfresh.views.PointFTypeEvaluator;
import com.epfresh.views.dialog.BaseDialogView;
import com.epfresh.views.dialog.MsgDialog;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author wangzhanghuan
 * @version 1.0
 * @date create 17-2-20
 * @Description
 */

public class DcGoodsDelegate implements LoadMoreListView.IXListViewListener, DataManager.OnCartCountChangeListener, View.OnClickListener {


    //topCategoryId 一级分类
    //categoryId 二级分类
    //categoryType 1,平台；2，自建


    //category/getNames
    // { parameters: {topCategoryId: '1级分类ID',categoryId: '二级分类ID',categoryType: '二级分类类型'}}

    BaseActivity activity;

    ListView lvCategory;

    LoadMoreListView lvProduct;

    TextView tvChoice;

    View vFilter;
    ImageView ivFilter;
    TextView tvFilter;
    View vAcceptOrder;

    MultiStateView msView;

    private List<ListGoods> listGoods = new ArrayList<>();
    private List<ProductCategory> list = new ArrayList<>();
    //    CategoryGoodsAdapter dcAdapter;
    CategoryGoodsAdapter listAdapter;


    TagPager tagPager = new TagPager();
    int PAGE_SIZE = 15;
    private DeliveryStoreListAdapter adapterGoods;
    GoodsParameters parameters = new GoodsParameters();
    //    DcCnt dcCnt = new DcCnt();
    private PtrMdFrameLayout ptrFrameLayout;


    DcFilterDelegate dcFilterDelegate;

    int currentPosition = 0;
    String currentGoodsId;
    Set<Integer> currentSet;
    List<String> names;
    List<String> marketIds;

    String topCategoryId;
    String categoryId;
    View v;

    StoreDetail storeDetail;

    private int serviceStoreId;

    public void setStoreDetail(StoreDetail storeDetail) {
        this.storeDetail = storeDetail;
        Log.e("setVisible","136");

        updateStoreStatus(storeDetail);
    }

    public DcGoodsDelegate(BaseActivity activity, View v) {
        this.activity = activity;
        this.v = v;
        initView();
        initCartView();
        dcFilterDelegate = new DcFilterDelegate(activity);
        dcFilterDelegate.setOnDismissListener(new BaseDialogView.OnDismissListener() {
            @Override
            public void onDismiss(Object o) {
                ivFilter.setImageResource(R.mipmap.down_arrow);
            }
        });
        dcFilterDelegate.dismiss();
        dcFilterDelegate.setOnFilter(new DcFilterDelegate.OnFilter() {
            @Override
            public void onFilter(Set<Integer> set, List<String> name) {
                currentSet = set;
                names = name;
                parameters.setNameIds(names);
                updateFilterStatus();
                refresh(false);
            }
        });
    }

    public View findViewById(int id) {
        return v.findViewById(id);
    }


    //二级分类列表选中，初始化
    public void updateList(String topCategoryId, List<ProductCategory> list, List<String> markets) {
        this.topCategoryId = topCategoryId;
        this.marketIds = markets;
        if (list != null) {
            currentPosition = 0;
            this.list.clear();
            this.list.addAll(list);
            listAdapter.notifyDataSetChanged();
            if (list.size() > 0) {
                ProductCategory productCategory = list.get(0);

                this.categoryId = productCategory.getId();
                clearFilterStatus();

                ProductCategory child = productCategory;
                String id = topCategoryId;

                String key = id + "|" + child.getId() + "|" + child.getType();
                //请求品类
                requestNames(id, child.getId(), child.getType());
                currentGoodsId = key;

                loadGoods(topCategoryId, this.categoryId, productCategory.getType(), null, marketIds);

                adapterGoods.setAcceptTime(productCategory.getBusinessTime());
                refresh(false);
            }
        }
    }

    private void loadGoods(String topCategoryId, String categoryId, String type, List<String> nameIds, List<String> marketIds) {
//                    parameters.setStoreId(storeId);
//                    parameters.setCategoryId(child.getId());
//                    parameters.setTopCategoryId(id);
//                    parameters.setCategoryType(child.getType());
//                    //清空选中，筛选状态
//                    parameters.setNameIds(null);
//                    parameters.setSelected(null);
//                    names = null;
//                    currentSet = null;
//                    updateFilterStatus();
//                    updateChoiceStatus();
        if (storeDetail != null)
            parameters.setStoreId(storeDetail.getId());
        parameters.setCategoryId(categoryId);
        parameters.setTopCategoryId(topCategoryId);
        parameters.setNameIds(nameIds);
        parameters.setCategoryType(type);
        if (marketIds != null && marketIds.size() == 0) {
            parameters.setMarketIds(null);
        } else {
            parameters.setMarketIds(marketIds);
        }
    }


    public void initView() {
        initHeadView();

        tvChoice = (TextView) findViewById(R.id.tv_choice);
        tvFilter = (TextView) findViewById(R.id.tv_filter);
        vFilter = findViewById(R.id.ll_filter);
        ivFilter = (ImageView) findViewById(R.id.iv_filter);
        tvChoice.setOnClickListener(this);
        vFilter.setOnClickListener(this);


        msView = (MultiStateView) findViewById(R.id.ms_view);
        msView.setViewForState(R.layout.loading_view, MultiStateView.VIEW_STATE_LOADING);
        msView.setViewForState(R.layout.empty_goods, MultiStateView.VIEW_STATE_EMPTY);
        msView.setViewForState(R.layout.error_view, MultiStateView.VIEW_STATE_ERROR);
        msView.setViewState(MultiStateView.VIEW_STATE_CONTENT);

        msView.setOnErrorClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                refresh(false);
            }
        });
        lvCategory = (ListView) findViewById(R.id.listview);

        lvProduct = (LoadMoreListView) findViewById(R.id.lv);

        vAcceptOrder = findViewById(R.id.tv_store_rest);

        if (listAdapter == null) {
            listAdapter = new CategoryGoodsAdapter(activity, list);
            lvCategory.setAdapter(listAdapter);
        }


        listAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ProductCategory storeCategoryItem = list.get(i);
                currentPosition = i;
                dcFilterDelegate.dismiss();
                if (storeCategoryItem != null) {


                        ProductCategory child = storeCategoryItem;
                        String id = topCategoryId;

                        String key = id + "|" + child.getId() + "|" + child.getType();
                        //请求品类
                        requestNames(id, child.getId(), child.getType());
                        currentGoodsId = key;


                    //---------------
                    categoryId = storeCategoryItem.getId();
                    parameters.setSelected(null);
                    loadGoods(topCategoryId, categoryId, storeCategoryItem.getType(), null, marketIds);

                    clearFilterStatus();
//                    parameters.setStoreId(storeId);
//                    parameters.setCategoryId(child.getId());
//                    parameters.setTopCategoryId(id);
//                    parameters.setCategoryType(child.getType());
//                    //清空选中，筛选状态
//                    parameters.setNameIds(null);
//                    parameters.setSelected(null);
//                    names = null;
//                    currentSet = null;
//                    updateFilterStatus();
//                    updateChoiceStatus();
//
                    adapterGoods.setAcceptTime(storeCategoryItem.getBusinessTime());
                    refresh(false);

                }
            }
        });

        adapterGoods = new DeliveryStoreListAdapter(activity, listGoods);

//        adapterGoods.setShowMarketName(true);
        lvProduct.noView();
        lvProduct.setAdapter(adapterGoods);
        lvProduct.setXListViewListener(this);
//        lvProduct.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                if (i < listGoods.size()) {
//                    ListGoods listGoods = CategoryGoodsDelegate.this.listGoods.get(i);
//                    String id = listGoods.getId();
//                    Intent intent = new Intent(activity, DetailGoodsActivity.class);
//                    intent.putExtra("id", id + "");
//                    activity.startActivity(intent);
//                }
//            }
//        });

        adapterGoods.setOnAddClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                ListGoods goods = listGoods.get(i);
                if (goods != null && goods.isAcceptOrders()) {
                    double cnt = goods.getMoq();
                    reqCartCnt(cnt, goods);
                    addAnim(view);
                } else {
                    T.toast("暂不接单");
                }
//                if (!storeDetail.isAcceptOrders()) {
//                    T.toast("店铺休息中");
//                } else {
//                    addCart(listGoods.get(i));
//                }
            }
        });
        adapterGoods.setOnCollectListener(new DeliveryStoreListAdapter.OnCartAddListener() {
            @Override
            public void onCartAdd(int type, int position, ListGoods goods, View v) {

                if (goods != null){


                    reqCollect(goods);
                }


            }
        });
        adapterGoods.setOnCartAddListener(new DeliveryStoreListAdapter.OnCartAddListener() {
            @Override
            public void onCartAdd(int type, int position, ListGoods goods, View v) {
                DataManager.getInstance().oftenListReFresh = true;
                if (type == 1) {//购物车手动输入
                    openDialog(goods);
                } else if (type == 2) {//添加
                    addCartCnt(goods, true, v);

                } else if (type == 3) {//减少
                    addCartCnt(goods, false, v);

                } else if (type == 5) {
                    String id = goods.getId();
                    Intent intent = new Intent(activity, DetailGoodsActivity.class);
                    intent.putExtra("id", id + "");
                    intent.putExtra("storeId",goods.getStoreId());
                    intent.putExtra("promotionItemId", goods.getPromotionItemId());
                    intent.putExtra("serviceStoreId",serviceStoreId);
                    activity.startActivity(intent);
                } else if (type == 10){

                    if(goods.getShoppingCarId()==null) {
                        Log.e("getShoppingCarId","_____null___"+goods.getShoppingCarId());
                        return;
                    }
                    openMsgDialog(goods, goods.getFastMessages());
                }

            }
        });
    }

    MsgDialog msgDialog;
    String msgNow;
    private void openMsgDialog( ListGoods goods, List<String> list) {
        //if(msgDialog==null)
            msgDialog = new MsgDialog(activity);
        msgDialog.setOnCommitListener(new MsgDialog.OnCommitListener() {
            @Override
            public void onCommit(String msg, String goodsId) {
                msgDialog.dismiss();
                msgNow = msg;
                saveMsg(msg,goodsId);
            }
        });
        msgDialog.show(goods.getShoppingCarId(),list,goods.getMsg());
    }

    OnRequestListener<Map<String, Object>> onSaveMsgRequestListener = new OnRequestListener<Map<String, Object>>() {
        @Override
        public Map<String, Object> jsonToObj(String s) {
            return new Gson().fromJson(s, new TypeToken<Map<String, Object>>() {
            }.getType());
        }

        @Override
        public void onFail(int i, Object o, Object o1) {

        }

        @Override
        public void onResponseError(int i, Object o, Object o1) {
            T.toast(o + "");//arg + ",请点击重试"

        }

        @Override
        public void onStart(Object o) {
            activity.showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<Map<String, Object>> responseEntity, Object o) {
            activity.hideProgressDialog();
            if(msgDialog!=null)
                msgDialog.dismiss();

            Map<String, Object> responseElement = responseEntity.getResponseElement();
            if (responseElement != null) {
                Object success = responseElement.get("success");
                if (success != null && success instanceof Boolean && ((Boolean) success)) {
/*                    groupList.get(msgPosition/1000).getResult().get(msgPosition%1000).setMerMsg(msgNow);
                    adapter.notifyDataSetChanged();*/
                    requestCount();
                }
            }
        }
    };

    public void saveMsg(String msg,String goodsId) {
        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_saveMsg);
        re.putParameter("merMsg", msg);
        re.putParameter("shoppingCarId", goodsId);
        ApplicationHelper.getInstance().requestSilent(re, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_saveMsg, onSaveMsgRequestListener);
    }
    public void clearFilterStatus() {
        names = null;
        currentSet = null;
        parameters.setSelected(null);
        updateFilterStatus();
        updateChoiceStatus();
    }


    public void addCartCnt(ListGoods goods, boolean isAdd, View v) {
        double min = goods.getMoq();
        double incr = goods.getIncr();
        double cnt = goods.getCount();
        double amount = cnt;


        if (isAdd) {
            amount = FormatUtil.countAdd(amount, incr);
        } else {
            amount = FormatUtil.countAdd(amount, -incr);
        }

//        if (FormatUtil.remainderZero(amount, goods.getInventoryAmount()) > 0) {
//            amount = goods.getInventoryAmount();
//            T.toast("库存不足");
//        } else
        if (isAdd) {
            addAnim(v);
        }
        if (isAdd && FormatUtil.remainderZero(amount, goods.getMoq()) < 0) {
            amount = min;
        }


        if (!isAdd && (FormatUtil.remainderZero(amount, 0) <= 0 || FormatUtil.remainderZero(amount, min) < 0)) {
            amount = 0;
            reqCartCnt(amount, goods);
            return;
        }
        amount = FormatUtil.countFormat(amount, incr, min, goods.getInventoryAmount());
        reqCartCnt(amount, goods);


    }


    public void updateStoreAcceptOrders(boolean isAcceptOrders) {
        if (storeDetail != null) {
            if (isAcceptOrders)
                storeDetail.setAcceptOrders(isAcceptOrders);
            Log.e("setVisible","488");

            updateStoreStatus(storeDetail);
        }
    }

    public void updateStoreStatus(StoreDetail storeDetail) {
        if (vAcceptOrder != null) {
            if (storeDetail != null && !storeDetail.isAcceptOrders()) {
                Log.e("setVisible","visible");
                vAcceptOrder.setVisibility(View.VISIBLE);

            } else {
                Log.e("setVisible","gone");
                vAcceptOrder.setVisibility(View.GONE);
            }
        }
    }

    private PtrHandler ptrHandler = new PtrHandler() {
        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, lvProduct, header) && listGoods.size() > 0;
        }

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            refresh(true);
        }
    };

    private void initHeadView() {
        ptrFrameLayout = (PtrMdFrameLayout) findViewById(R.id.fragment_ptr_category_ptr_frame);
        ptrFrameLayout.setPtrHandler(ptrHandler);

    }


    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.iv_cart:
                cart();
                break;
            case R.id.tv_total:
                cart();
                break;

            case R.id.ll_filter://切换筛选
                MobclickAgent.onEvent(activity, "Click_Filter_BulkStore");/*统计点击*/
                openFilter();
                break;
            case R.id.tv_choice:
                MobclickAgent.onEvent(activity, "Click_Selected_BulkStore");/*统计点击*/
                choice();
                break;

        }
    }

    //查看已选切换
    private void choice() {
        dcFilterDelegate.dismiss();
        Boolean selected = parameters.getSelected();
        if (selected != null && selected) {
            parameters.setSelected(null);
        } else {
            parameters.setSelected(true);
        }
        updateChoiceStatus();
        refresh(false);

    }


    public void updateFilterStatus() {
        if (names != null && names.size() > 0) {//有筛选条件
            tvFilter.setTextColor(Color.parseColor("#009983"));
        } else {
            tvFilter.setTextColor(Color.parseColor("#858585"));
        }
    }

    public void updateChoiceStatus() {
        Boolean selected = parameters.getSelected();
        if (selected != null && selected) {
            tvChoice.setTextColor(Color.parseColor("#009983"));
        } else {
            tvChoice.setTextColor(Color.parseColor("#858585"));
        }
    }


    HashSet<String> goodCollectSet = new HashSet<>();
    private void reqCollect(ListGoods goods) {

        if (goodCollectSet.contains(goods.getUniqueKey())){
            return;
        }
        Boolean show = goods.isShow();
        goods.setShow(!show);
        adapterGoods.notifyDataSetChanged();
        goodCollectSet.add(goods.getUniqueKey());
        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_frequent);


//        private Long promotionItemId;//促销场次ID
//        private Long promotionId;//促销ID
//        private Integer promotionType;//促销场次ID
        re.putParameter("productId", goods.getUniqueKey());

        re.putParameter("show", !show);

        RequestTag tag = new RequestTag();
        tag.arg1 = com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_frequent;
        tag.arg2 = goods;


        activity.request(re, tag, new OnRequestListener< Map<String,Boolean> >() {
            @Override
            public Map<String,Boolean> jsonToObj(String responseStr) {
                return JsonUtils.fromJsonMap(responseStr,Boolean.class);
            }

            @Override
            public void onFail(int failCode, Object arg, Object tag) {
                if (tag != null && tag instanceof RequestTag){
                    RequestTag requestTag = (RequestTag) tag;
                    tag = requestTag.arg2;
                    if (tag != null && tag instanceof ListGoods) {
                        ListGoods g = (ListGoods) tag;
                        g.setShow(!g.isShow());
                        goodCollectSet.remove(g.getUniqueKey());
                        adapterGoods.notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onResponseError(int failCode, Object arg, Object tag) {

                if (tag != null && tag instanceof RequestTag){
                    RequestTag requestTag = (RequestTag) tag;
                    tag = requestTag.arg2;
                    if (tag != null && tag instanceof ListGoods) {
                        ListGoods g = (ListGoods) tag;
                        goodCollectSet.remove(g.getUniqueKey());
                        g.setShow(!g.isShow());
                        adapterGoods.notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onStart(Object tag) {

            }

            @Override
            public void onResponse(ResponseEntity< Map<String,Boolean> > response, Object tag) {

                ListGoods g = null;
                if (tag != null && tag instanceof RequestTag){
                    RequestTag requestTag = (RequestTag) tag;
                    tag = requestTag.arg2;
                    if (tag != null && tag instanceof ListGoods) {
                        g = (ListGoods) tag;
                        goodCollectSet.remove(g.getUniqueKey());
                    }
                }

                if (response != null){
                    Map<String, Boolean> responseElement = response.getResponseElement();
                    if(responseElement != null){
                        Boolean show = responseElement.get("show");
                        if(show != null ){
                            if (g != null ){
                                g.setShow(show);
                                adapterGoods.notifyDataSetChanged();

                            }

                        }
                    }
                }
            }
        });

    }

    Map<String, List<ProductCategory>> mapNames = new HashMap<>();

    public void requestNames(String topCategoryId, String categoryId, String categoryType) {

        String key = topCategoryId + "|" + categoryId + "|" + categoryType;
//        if (mapNames.containsKey(key)) {
//            return;
//        }

        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_category_getNames);

        re.putParameter("topCategoryId", topCategoryId);
        re.putParameter("categoryId", categoryId);
        re.putParameter("categoryType", categoryType);
        if (storeDetail != null)
            re.putParameter("storeId", storeDetail.getId());

        RequestTag tag = new RequestTag();

        tag.tag = com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_category_getNames;
        tag.arg1 = key;

//        ApplicationHelper.getInstance().requestSilent(re, tag, onNamesRequestListener);



        tag.type = RequestTag.TYPE_CURRENT;

        activity.request(re, tag, onNamesRequestListener);
    }


    OnRequestListener<List<ProductCategory>> onNamesRequestListener = new OnRequestListener<List<ProductCategory>>() {
        @Override
        public List<ProductCategory> jsonToObj(String s) {
            return new Gson().fromJson(s, new TypeToken<List<ProductCategory>>() {
            }.getType());
        }

        @Override
        public void onFail(int i, Object o, Object o1) {

        }

        @Override
        public void onResponseError(int i, Object o, Object o1) {

        }

        @Override
        public void onStart(Object o) {

        }

        @Override
        public void onResponse(ResponseEntity<List<ProductCategory>> responseEntity, Object o) {
            if (responseEntity != null) {

                List<ProductCategory> responseElement = responseEntity.getResponseElement();

                if (responseElement != null && o != null && o instanceof RequestTag) {
                    RequestTag tag = (RequestTag) o;
                    String key = tag.arg1;
                    mapNames.put(key, responseElement);
                    if (key.equals(currentGoodsId) && dcFilterDelegate.isShow()) {//当前列表

                        dcFilterDelegate.show(responseElement, currentSet);
                    }
                }

            }
        }
    };


    //商品筛选切换
    private void openFilter() {

        if (dcFilterDelegate.isShow()) {
            dcFilterDelegate.dismiss();
            ivFilter.setImageResource(R.mipmap.down_arrow);
        } else {
            ivFilter.setImageResource(R.mipmap.up_arrow);

            List<ProductCategory> productCategories = null;
            if (currentGoodsId != null) {
                productCategories = mapNames.get(currentGoodsId);
            }
            dcFilterDelegate.show(productCategories, currentSet);
//            if (currentPosition < list.size()) {
//                ProductCategory productCategory = list.get(currentPosition);
//                if (currentGoodsId != null) {
//
//                }
//                dcFilterDelegate.show(productCategory.getNames(), currentSet);
//            }
        }

    }


    public void dismissFilter() {
        if (dcFilterDelegate != null && dcFilterDelegate.isShow()) {
            dcFilterDelegate.dismiss();
            ivFilter.setImageResource(R.mipmap.down_arrow);
        }
    }

    public void cart() {
        if (ApplicationHelper.getInstance().getUser().getAccess_token() == null || "".equals(ApplicationHelper.getInstance().getUser().getAccess_token())) {
            Intent intent = new Intent(activity, LoginActivity.class);
            intent.putExtra("relogin", true);
            activity.startActivity(intent);
            return;
        }

        Intent intent = new Intent(activity, HomeActivity.class);
        intent.putExtra("home_tab_index", 2);
        activity.startActivity(intent);
    }


    public void refresh(boolean isPullFresh) {
        if (!isPullFresh) {
            listGoods.clear();
            adapterGoods.notifyDataSetChanged();
        }
        lvProduct.resetNoMore();
        parameters.setPageSize(PAGE_SIZE);
        parameters.setPageNumber(0);
        request(parameters, isPullFresh);
    }


    @Override
    public void onLoadMore() {
        int number = tagPager.getNumber();
        parameters.setPageSize(PAGE_SIZE);
        parameters.setPageNumber(number + 1);
        request(parameters, true);
    }


    public void updateViewStatus(RequestTag requestTag) {
        ptrFrameLayout.refreshComplete();
        if (tagPager.isLast()) {
            lvProduct.noMore();
        } else {
            lvProduct.stopLoadMore();
        }
    }

    private OnRequestListener onRequestListener = new OnRequestListener<ContentEntity<ListGoods>>() {
        @Override
        public ContentEntity<ListGoods> jsonToObj(String s) {
            return new Gson().fromJson(s, new TypeToken<ContentEntity<ListGoods>>() {
            }.getType());
        }

        @Override
        public void onFail(int i, Object o, Object tag) {
            if (listGoods.size() == 0) {
                msView.setViewState(MultiStateView.VIEW_STATE_ERROR);
            }
        }

        @Override
        public void onResponseError(int i, Object o, Object tag) {
            if (listGoods.size() == 0) {
                msView.setViewState(MultiStateView.VIEW_STATE_ERROR);
            }

        }

        @Override
        public void onStart(Object o) {

            if (o instanceof RequestTag) {
                RequestTag tag = (RequestTag) o;
                String arg1 = tag.arg1;
                if (!"1".equals(arg1) && listGoods.size() == 0) {
                    msView.setViewState(MultiStateView.VIEW_STATE_LOADING);
                }

            }
        }

        @Override
        public void onResponse(ResponseEntity<ContentEntity<ListGoods>> responseEntity, Object tag) {


            ContentEntity<ListGoods> responseElement = responseEntity.getResponseElement();
            RequestTag requestTag = (RequestTag) tag;

            if (responseElement != null) {
                msView.setViewState(MultiStateView.VIEW_STATE_CONTENT);
                List<ListGoods> content = responseElement.getContent();
                if (content.size() != 0) {
                    serviceStoreId = responseElement.getServiceStoreId();
                }
                if (requestTag.action == 0) {
                    listGoods.clear();
                }
                if (content != null)
                    listGoods.addAll(content);
//                updateDcCnt();
                requestCount();
                if (content != null && content.size() > 0) {
                    ListGoods listGoods = content.get(0);
                    updateStoreAcceptOrders(listGoods.isAcceptOrders());
                }
//                dcAdapter.notifyDataSetChanged();
                tagPager.setLast(responseElement.getLast());
                Log.d("tagPager", "tagPager:" + tagPager);
                tagPager.setNumber(responseElement.getNumber());
                tagPager.setSize(responseElement.getSize());
                tagPager.setTotalElements(responseElement.getTotalElements());

            } else {


            }

            updateViewStatus(requestTag);
            if (listGoods.size() == 0) {
                msView.setViewState(MultiStateView.VIEW_STATE_EMPTY);
            }
        }
    };

    private void updateCount(int count) {
//        UnreadMsgUtils.show(msgCount, count);
//        if (count > 0) {
//            ivCart.setImageResource(R.mipmap.cart_red);
//            tvTotal.setEnabled(true);
//            tvTotal.setTextColor(Color.WHITE);
//            tvTotal.setText("去结算");
//        } else {
//            tvTotal.setText("购物车是空的");
//            ivCart.setImageResource(R.mipmap.cart_gray);
//            tvTotal.setEnabled(false);
//            tvTotal.setTextColor(Color.parseColor("#434343"));
//        }
    }

    public void request(GoodsParameters parameters, boolean isPullFresh) {

        if (list.size() == 0) {
            ptrFrameLayout.refreshComplete();
            return;
        }
        RequestEntityPurchase<GoodsParameters> re = new RequestEntityPurchase<>();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_list);
        if (parameters != null) {
            parameters.setType("1");
        }
        re.setParameters(parameters);
        RequestTag requestTag = new RequestTag();
        requestTag.tag = com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_list;
        requestTag.action = parameters.getPageNumber();
        requestTag.type = RequestTag.TYPE_CURRENT;
        if (isPullFresh) {//下拉
            requestTag.arg1 = "1";
        } else {
            requestTag.arg1 = "";
        }
        activity.request(re, requestTag, onRequestListener);
    }


    private void load() {


    }


    @Override
    public void onCartCountChange(int count) {

    }

    public void requestCount() {
        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_cnt);

        if (storeDetail != null)
            re.putParameter("storeId", storeDetail.getId());
        re.putParameter("cityId", ApplicationHelper.getInstance().getCity().getCityId());
        re.putParameter("accountId", ApplicationHelper.getInstance().getUser().getAccountId());
        re.putParameter("wholeSalesType", "2");
        ApplicationHelper.getInstance().requestSilent(re, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_cnt, onCartCntRequestListener);
    }


    OnRequestListener<CarCntResponse> onCartCntRequestListener = new OnRequestListener<CarCntResponse>() {
        @Override
        public CarCntResponse jsonToObj(String s) {
            return new Gson().fromJson(s, CarCntResponse.class);
        }

        @Override
        public void onFail(int i, Object o, Object o1) {

        }

        @Override
        public void onResponseError(int i, Object o, Object o1) {

        }

        @Override
        public void onStart(Object o) {

        }

        @Override
        public void onResponse(ResponseEntity<CarCntResponse> responseEntity, Object o) {
//            dcCnt = responseEntity.getResponseElement();
            carCntResponse = responseEntity.getResponseElement();
            if (carCntResponse != null) {
                carCntResponse.init();
            }
            updateCnt();
        }
    };

    CarCntResponse carCntResponse;

    public void updateCnt() {
//        if (carCntResponse != null) {
//            if (listGoods != null) {
//                for (int i = 0; i < listGoods.size(); i++) {
//                    ListGoods item = listGoods.get(i);
//
//                    item.setCount(carCntResponse.getGoodsCount(item.getIdPlus()));
//
//                    Log.e("listGoods", "cnt:" + item.getCount() + "---id:" + item.getId());
//                }
//            }
//
//            if (adapterGoods != null) {
//                adapterGoods.notifyDataSetChanged();
//            }
//
//        }

        if (carCntResponse != null) {
            if (list != null) {
                for (int j = 0; j < list.size(); j++) {
                    ProductCategory storeCategoryItem = list.get(j);
                    String categoryId = storeCategoryItem.getId();

                    if (categoryId != null) {
                        if ("-2".equals(categoryId)){
                            storeCategoryItem.setCount(carCntResponse.getPromotionCount(topCategoryId));
                        }else {
                            storeCategoryItem.setCount(carCntResponse.getCategoryCount(categoryId));
                        }
                    }
                }
            }

            if (listGoods != null) {
                for (int i = 0; i < listGoods.size(); i++) {
                    ListGoods item = listGoods.get(i);

                    if (cartHelper != null && cartHelper.isRequesting(item.getUniqueKey())){
                        continue;
                    }

                    item.setCount(carCntResponse.getGoodsCount(item.getIdPlus()));
/*                   for (String key : carCntResponse.getMerMsgMap().keySet()) {
                        System.out.println("key= "+ key + " and value= " + carCntResponse.getMerMsgMap().get(key));
                    }*/
                    item.setShoppingCarId(carCntResponse.getShopingCarId(item.getIdPlus()));
                    if(carCntResponse!=null&&carCntResponse.getMerMsgMap()!=null)
                        item.setMsg(carCntResponse.getMerMsgMap().get(item.getShoppingCarId()));
                }
            }
            if (listAdapter != null) {
                listAdapter.notifyDataSetChanged();
            }
            if (adapterGoods != null) {
                adapterGoods.notifyDataSetChanged();
            }
        }

    }


    public void updateGoodsCollect(){
        if (cartHelper != null){
            int size = listGoods.size();
            for (int i = 0; i< size; i++){

                ListGoods listGoods = this.listGoods.get(i);
                Boolean b = DataManager.getInstance().getCollectMap(listGoods.getUniqueKey());
                Log.e("cartHelper","cartHelper:"+DataManager.getInstance().collectMap);
                if (b != null){
                    listGoods.setShow(b);
                }
            }

            adapterGoods.notifyDataSetChanged();
            DataManager.getInstance().clearCollectMap();
        }
    }


    CartHelper cartHelper = new CartHelper();
    public void reqCartCnt(double productCount, ListGoods goods) {
        if (goods == null){
            return;
        }

        if (goods != null) {
            goods.setCount(productCount);
            adapterGoods.notifyDataSetChanged();
        }
        if (!cartHelper.checkIsCartRequesting(goods)){
            updateCartCnt(productCount,goods);
        }else {

        }
    }

    public void responseCartCnt(boolean isFail,ListGoods goods,double cnt){
        if (isFail){
            cartHelper.responseCartFail(goods);
        }else {
            cartHelper.responseCartSuccess(goods,cnt);
        }
    }

    public void updateCartCnt(double productCount, final ListGoods goods) {

        if (activity == null) {
            return;
        }
        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_add);


//        private Long promotionItemId;//促销场次ID
//        private Long promotionId;//促销ID
//        private Integer promotionType;//促销场次ID
/*
        re.putParameter("promotionItemId", goods.getPromotionItemId());

        re.putParameter("shoppingCarId", goods.getShoppingCarId());
        re.putParameter("productUnitPrice", goods.getPriceOnly());
        re.putParameter("productId", goods.getId());
        re.putParameter("salesType", goods.getType());
        re.putParameter("versionId", goods.getLastSnapshotId());
        re.putParameter("cityId", ApplicationHelper.getInstance().getCity().getCityId());
        re.putParameter("productCount", productCount);
        re.putParameter("accountId", ApplicationHelper.getInstance().getUser().getAccountId());
*/
//        re.putParameter("specId", goods.getId());
        re.putParameter("specId", goods.getProductSpecPrice().getProductSpecId());
        if(goods.getPromotion()!=null)
            re.putParameter("specPromotionItemId", goods.getPromotion().getItemId());
        re.putParameter("count", productCount);
        if (serviceStoreId != -1) {
            re.putParameter("serviceStoreId", serviceStoreId);
        }
        RequestTag tag = new RequestTag();
        tag.tag = goods;
//        tag.tag = "appOrder/updateShoppingCarProductCount";
        tag.arg1 = productCount + "";
        tag.arg2 = productCount;
//        tag.arg2 = goods;

        tag.type = RequestTag.TYPE_CURRENT;
        if (cartHelper != null && goods !=null){
            cartHelper.updateRequest(goods.getUniqueKey());
        }
        activity.request(re, tag, new OnRequestListener<AddCarResponse>() {
            @Override
            public AddCarResponse jsonToObj(String s) {
                return new Gson().fromJson(s, AddCarResponse.class);
            }

            @Override
            public void onFail(int i, Object o, Object o1) {
                activity.hideProgressDialog();
                RequestTag tag = null;

                if (o1 instanceof RequestTag) {
                    tag = (RequestTag) o1;
                    String arg1 = tag.arg1;
                    Object arg2 = tag.arg2;
                    Object o2 = tag.tag;
                    if (arg1 != null && o2 != null && o2 instanceof ListGoods) {
                        ListGoods goods = (ListGoods) o2;
//                        BigDecimal a = new BigDecimal(arg1).setScale(2, BigDecimal.ROUND_HALF_UP);
                        if (arg2 != null && arg2 instanceof Double) {
//                            goods.setCount((Double) arg2);
                            responseCartCnt(true,goods,-1);
                            adapterGoods.notifyDataSetChanged();
                            T.toast(goods.getTitle() + " 添加购物车失败");
                        }
                    }
                }
            }

            @Override
            public void onResponseError(int i, Object o1, Object o) {
                activity.hideProgressDialog();
                RequestTag tag = null;

                if (i / 100 == 4) {
                    T.toast(o1 + "");
                }
                if (o instanceof RequestTag) {
                    tag = (RequestTag) o;
                    String arg1 = tag.arg1;
                    Object arg2 = tag.arg2;
                    Object o2 = tag.tag;
                    if (arg1 != null && o2 != null && o2 instanceof ListGoods) {
                        ListGoods goods = (ListGoods) o2;
//                        BigDecimal a = new BigDecimal(arg1).setScale(2, BigDecimal.ROUND_HALF_UP);

                        if (arg2 != null && arg2 instanceof Double) {
                            responseCartCnt(true,goods,-1);
                            adapterGoods.notifyDataSetChanged();

                            if (i / 100 != 4) {
                                T.toast(goods.getTitle() + " 添加购物车失败");
                            }
                        }
                    }
                }
            }

            @Override
            public void onStart(Object o) {
                //activity.showProgressDialog();
            }

            @Override
            public void onResponse(ResponseEntity<AddCarResponse> responseEntity, Object o) {
                activity.hideProgressDialog();

                AddCarResponse responseElement = responseEntity.getResponseElement();
                if (responseElement != null) {
                    DataManager.getInstance().oftenListReFresh = true;

                    RequestTag tag = null;
                    if (o instanceof RequestTag) {
                        tag = (RequestTag) o;
                        String arg1 = tag.arg1;
                        Object o2 = tag.tag;
                        if (arg1 != null && o2 != null && o2 instanceof ListGoods) {
                            ListGoods goods = (ListGoods) o2;
////                        BigDecimal a = new BigDecimal(arg1).setScale(2, BigDecimal.ROUND_HALF_UP);
//                        goods.setCount(responseElement.getProductCnt());
                            goods.setShoppingCarId(responseElement.getShoppingCarId());
//                            DataManager.getInstance().setCartCntStatus(responseElement.getshoppingCarCnt());
                            DataManager.getInstance().updateCartCnt();
                            responseCartCnt(false,goods,responseElement.getProductCnt());
                            adapterGoods.notifyDataSetChanged();

                            if (carCntResponse == null) {
                                adapterGoods.notifyDataSetChanged();
                                listAdapter.notifyDataSetChanged();
                            } else {

                                carCntResponse.putCategoryCount(responseElement.getCategoryId()+"|"+responseElement.getCategoryType(), responseElement.getCategoryCnt());
                                carCntResponse.putTopCategoryCount(responseElement.getTopCategoryId(), responseElement.getTopCategoryCnt());
                                carCntResponse.putPromotionCount(responseElement.getTopCategoryId(), responseElement.getPromotionCnt());
                                carCntResponse.putGoodsCount(goods.getIdPlus(), goods.getCount());
                                carCntResponse.putShopingCarId(goods.getIdPlus(),responseElement.getShoppingCarId());
                                if(responseElement.getProductCnt()==0){
                                    carCntResponse.getMerMsgMap().remove(responseElement.getShoppingCarId());
                                }
                                updateCnt();
                            }
                        }
                    }


                }
            }
        });

    }


    public void openDialog(final ListGoods cartGood) {
        if (activity == null) {
            return;
        }
        final Dialog dialog = new Dialog(activity, R.style.no_title_dialog);

        dialog.setContentView(R.layout.dialog_cart_add);
        ImageView ivAdd = (ImageView) dialog.findViewById(R.id.iv_add);
        ImageView ivRemove = (ImageView) dialog.findViewById(R.id.iv_remove);

        final EditText ed = (EditText) dialog.findViewById(R.id.ed_price);

        ed.setText(FormatUtil.subZeroAndDot(cartGood.getCount() + ""));
        ed.setSelection(ed.length());
        CashierInputFilter cashierInputFilter = new CashierInputFilter();
        cashierInputFilter.MAX_VALUE = 999999;
        ed.setFilters(new InputFilter[]{cashierInputFilter});
        ivAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = ed.getText().toString();
                double min = cartGood.getMoq();
                double incr = cartGood.getIncr();
                double cnt = min;
                Log.d("cnt", "s:" + s);
                if (s.length() > 0) {
                    cnt = Double.valueOf(s);
                }
                double amount = cnt;


//                if (FormatUtil.remainderZero(amount, cartGood.getInventoryAmount()) > 0) {
//                    amount = cartGood.getInventoryAmount();
//                }

                amount = FormatUtil.countAdd(amount, incr);
//                if (FormatUtil.remainderZero(amount, cartGood.getInventoryAmount()) > 0) {
//                    amount = cartGood.getInventoryAmount();
//                }


                cartGood.setCount(amount);
                ed.setText(FormatUtil.subZeroAndDot(amount + ""));
                ed.setSelection(ed.length());
            }
        });
        ivRemove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = ed.getText().toString();
                double min = cartGood.getMoq();
                double incr = cartGood.getIncr();
                double cnt = min;
                Log.d("cnt", "s:" + s);
                if (s.length() > 0) {
                    cnt = Double.valueOf(s);
                }
                double amount = cnt;
                if (amount < cartGood.getMoq()) {
                    amount = cartGood.getMoq();
                }

                amount = FormatUtil.countSubtract(amount, incr);
                if (amount < cartGood.getMoq()) {
                    amount = cartGood.getMoq();
                }
                cartGood.setCount(amount);
                ed.setText(FormatUtil.subZeroAndDot(amount + ""));
                ed.setSelection(ed.length());
            }
        });
        dialog.findViewById(R.id.negativeButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm.isActive()) {
                    imm.hideSoftInputFromWindow(ed.getApplicationWindowToken(), 0);
                }
                dialog.dismiss();
            }
        });

        dialog.findViewById(R.id.positiveButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double productCount = cartGood.getCount();
                String s = ed.getText().toString();
                double min = cartGood.getMoq();
                double incr = cartGood.getIncr();
                double cnt = min;
                Log.d("cnt", "s:" + s);
                if (s.length() > 0) {
                    cnt = Double.valueOf(s);
                }
                if (cnt < 0.01 || cnt < min) {
                    T.toast("不能少于" + FormatUtil.subZeroAndDot(min + ""));
                    cnt = FormatUtil.countFormat(cnt, incr, min);
                    ed.setText(FormatUtil.subZeroAndDot(cnt + ""));
                    ed.setSelection(ed.getText().length());
                    return;
                }


//                if (cnt > cartGood.getInventoryAmount()) {
//                    T.toast("超过库存");
//                    cnt = FormatUtil.countFormat(cartGood.getInventoryAmount(), incr, min);
//
//                    ed.setText(FormatUtil.subZeroAndDot(cnt + ""));
//                    ed.setSelection(ed.getText().length());
//                    return;
//                }
                incr = incr < 0.01 ? min : incr;

                if (FormatUtil.isRemainder(cnt, incr, min)) {
                    cnt = FormatUtil.countFormat(cnt, incr, min);
                    Log.e("cnt:", "cnt:" + FormatUtil.subZeroAndDot(cnt + ""));
                    ed.setText(FormatUtil.subZeroAndDot(cnt + ""));
                    ed.setSelection(ed.getText().length());
                    return;
                }

//                cartGood.setCount(cnt);
                reqCartCnt(cnt, cartGood);
                adapterGoods.notifyDataSetChanged();
                InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm.isActive()) {
                    imm.hideSoftInputFromWindow(ed.getApplicationWindowToken(), 0);
                }
                dialog.dismiss();
            }
        });

        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {

            }
        });

        dialog.show();
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                InputMethodManager inputManager =
                        (InputMethodManager) ed.getContext().getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(ed, 0);
            }
        }, 200);
    }


    View shoppingCartView;
    ViewGroup mainLayout;
//    View lvCart;


    private void initCartView() {
        AppActivity appActivity = activity;
        if (appActivity instanceof DcStoreActivity) {
            shoppingCartView = ((DcStoreActivity) appActivity).getvCart();
            mainLayout = ((DcStoreActivity) appActivity).getMainView();
//            lvCart = lvProduct;
        }
    }

    public void addAnim(View view) {
        int[] addLocation = new int[2];
        int[] cartLocation = new int[2];
//        int[] lvCartLocation = new int[2];
        view.getLocationInWindow(addLocation);
        shoppingCartView.getLocationInWindow(cartLocation);
//        lvCart.getLocationInWindow(lvCartLocation);

        PointF startP = new PointF();
        PointF endP = new PointF();
        PointF controlP = new PointF();

        startP.x = addLocation[0];
        startP.y = addLocation[1];
        endP.x = cartLocation[0] + LocalDisplay.dp2px(10);
        endP.y = cartLocation[1] - activity.getResources().getDimensionPixelSize(R.dimen.bottom_nav_ic_height);
        controlP.x = endP.x;
        controlP.y = startP.y;
        Log.e("location", "s===============");
        Log.i("location", "sw:" + LocalDisplay.SCREEN_WIDTH_PIXELS);
        Log.i("location", "sh:" + LocalDisplay.SCREEN_HEIGHT_PIXELS);
        Log.i("location", "sx:" + startP.x);
        Log.i("location", "sy:" + startP.y);
        Log.i("location", "ex:" + endP.x);
        Log.i("location", "ey:" + endP.y);
        Log.e("location", "e===============");

        final FakeAddImageView fakeAddImageView = new FakeAddImageView(activity);
        mainLayout.addView(fakeAddImageView);
        fakeAddImageView.setImageResource(R.drawable.cart_bezier);
        fakeAddImageView.getLayoutParams().width = LocalDisplay.dp2px(10);
        fakeAddImageView.getLayoutParams().height = LocalDisplay.dp2px(10);
        fakeAddImageView.setVisibility(View.VISIBLE);
        ObjectAnimator addAnimator = ObjectAnimator.ofObject(fakeAddImageView, "mPointF",
                new PointFTypeEvaluator(controlP), startP, endP);
        addAnimator.setInterpolator(new AccelerateInterpolator());
        addAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
                fakeAddImageView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                fakeAddImageView.setVisibility(View.GONE);
                mainLayout.removeView(fakeAddImageView);
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
        ObjectAnimator scaleAnimatorX = new ObjectAnimator().ofFloat(shoppingCartView, "scaleX", 0.6f, 1.0f);
        ObjectAnimator scaleAnimatorY = new ObjectAnimator().ofFloat(shoppingCartView, "scaleY", 0.6f, 1.0f);
        scaleAnimatorX.setInterpolator(new AccelerateInterpolator());
        scaleAnimatorY.setInterpolator(new AccelerateInterpolator());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(scaleAnimatorX).with(scaleAnimatorY).after(addAnimator);
        animatorSet.setDuration(340);
        animatorSet.start();

    }

}
